class DatasheetsController < ApplicationController
	before_filter :login_required, :except => [:index]
	
  def index
    @datasheets = Datasheet.find(:all)
  end

  def new
    @datasheet = Datasheet.new
    @page = Page.find(params[:page])
  end

  def create
    @datasheet = Datasheet.new(params[:datasheet])
    @page = Page.find(params[:page])
    
    @page.datasheets << @datasheet
    
    if @datasheet.save
      flash[:notice] = 'Datasheet was successfully uploaded.'

			redirect_to :controller => @page.section.name, :action => :show, :id => @page
    else
      render :action => "new"
    end
  end

  def destroy
    @datasheet = Datasheet.find(params[:id])
    @datasheet.destroy

    respond_to do |format|
      format.html { redirect_to datasheets_url }
      format.xml  { head :ok }
    end
  end
end